package com.lhc.web.controller;

import com.lhc.web.dao.UserMapper;
import com.lhc.web.domain.UserDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @Author lhc
 * @Date 2021/8/10 11:06
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    PasswordEncoder passwordEncoder;

    @GetMapping("/findAll")
    public List<UserDomain> findAll() {
        String password = passwordEncoder.encode("123456");
        List<UserDomain> userDomains = userMapper.selectAll();
        for (UserDomain userDomain : userDomains) {
            if (Objects.equals(userDomain.getId(), "8a8085fa7b2f1fde017b2f6295970004")) {
                userDomain.setUserPassword(password);
                userMapper.updateByPrimaryKey(userDomain);
            }
        }
        return userDomains;
    }
}